<?php

namespace App\Http\Controllers\Ajax;

use App\Common\Constant\Params;
use App\Common\Constant\Status;
use App\Services\IPayService;
use App\Services\IWalletService;
use App\Services\IWeixinService;
use Illuminate\Http\Request;
use WxPayConfig;

/**
 * 支付
 * Class PayController
 * @package App\Http\Controllers\Ajax
 */
class PayController extends BaseController
{

    /**
     * 根据师傅交易记录流水号检查交易是否已成功
     * @param Request $request
     */
    public function checkPaymentSuccess(Request $request, IPayService $payService)
    {
        if ($request->isMethod('post') && $request->has('trade_number')){
            $payService->setPaymentMethod($request->has('payment_method'));
            return $this->renderJson($payService->checkPaymentSuccess($request->input('trade_number')) ? Status::PAYMENT_SUCCESS : Status::PAYMENT_FAIL);
        }
        return $this->renderJson(Status::ERROR);
    }

    /**
     * 用钱包余额支付
     * @param Request $request
     * @param IPayService $payService
     */
    public function balancePay(Request $request, IPayService $payService,IWalletService $walletService){
        if ($request->isMethod('post') && $request->has('trade_number')){
            $ret = $walletService->pay($request->input('trade_number'));
            if ($ret === Status::PAYMENT_SUCCESS){
                return $this->renderJson(Status::SUCCESS);
            }else{
                return $this->renderJson($ret);
            }
        }
        return $this->renderJson(Status::ERROR);
    }

}
